<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/09/03
 * Time: 14:58
 */

namespace business\datacenter\repositories;

use yii\db\Query;

class SupplierTenderingRepository
{
    /**
     * 数据连接
     * @var \yii\db\Connection
     */
    private $db;

    public function __construct()
    {
        $this->db = \Yii::$app->db;
    }

    /**
     * 通过供应商ID获取招标报名分类信息
     * @param string $supplierId
     * @param string $fields
     * @return array
     */
    public function getSupplierAnnouncementsItemBySupplierId
    (
        $supplierId = '',
        $fields = 'r.bid_announcement_uid
        , r.register_date
        , c.category_code
        , b.category_name'
    ) {
        if (!empty($supplierId)) {
            return (new Query())
                ->from('`b2b_bidding`.`bid_announcements_register` r')
                ->select($fields)
                ->innerJoin('`b2b_bidding`.`bid_announcement_categories` c', 'r.bid_announcement_uid = c.bid_announcement_uid')
                ->innerJoin('`b2b_bidding`.`bid_announcements` a', 'r.bid_announcement_uid = a.uid')
                ->innerJoin('`b2b_parameter`.`bsp_basic_forest` b', 'b.category_code = c.category_code')
                ->innerJoin('`b2b_company`.`uuc_supplier_basic` d', 'r.supplier_id = d.supplier_id')
                ->where(['b.category_status' => 1, 'r.supplier_id' => $supplierId])
                ->andWhere(['NOT IN', 'r.state', [-1, 0]])
                ->andWhere(['NOT LIKE', 'company_name', 'test'])
                ->createCommand($this->db)
                ->queryAll();
        }

        return [];
    }
}
